<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title>服务合同信息</title>
	<script type="text/javascript" src="plug-in/mutiLang/zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/jquery/jquery-1.8.3.js"></script>
	<script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
	<%--<script type="text/javascript" src="plug-in/"></script>--%>
	<script type="text/javascript" src="plug-in/tools/dataformat.js"></script>
	<link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/default/easyui.css" type="text/css"></link>
	<link rel="stylesheet" href="plug-in/easyui/themes/icon.css" type="text/css"></link>
	<link rel="stylesheet" type="text/css" href="plug-in/accordion/css/accordion.css">
	<script type="text/javascript" src="plug-in/easyui/jquery.easyui.min.1.3.2.js"></script>
	<script type="text/javascript" src="plug-in/easyui/locale/zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/tools/syUtil.js"></script>
	<script type="text/javascript" src="plug-in/easyui/extends/datagrid-scrollview.js"></script>
	<script type="text/javascript" src="plug-in/My97DatePicker/WdatePicker.js"></script>
	<link rel="stylesheet" href="plug-in/tools/css/common.css" type="text/css"></link>
	<script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js"></script>
	<script type="text/javascript" src="plug-in/tools/curdtools_zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/tools/easyuiextend.js"></script>
	<script type="text/javascript" src="plug-in/jquery-plugs/hftable/jquery-hftable.js"></script>
	<link rel="stylesheet" href="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css" type="text/css"></link>
	<script type="text/javascript" src="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.min.js"></script>
	<link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css" />
	<script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>

</head>
<body>
<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="cbsContractController.do?doUpdate" tiptype="1">
<input id="id" name="id" type="hidden" value="${cbsContractPage.id }">
<input id="createName" name="createName" type="hidden" value="${cbsContractPage.createName }">
<input id="createBy" name="createBy" type="hidden" value="${cbsContractPage.createBy }">
<input id="createDate" name="createDate" type="hidden" value="${cbsContractPage.createDate }">
<input id="updateName" name="updateName" type="hidden" value="${cbsContractPage.updateName }">
<input id="updateBy" name="updateBy" type="hidden" value="${cbsContractPage.updateBy }">
<input id="updateDate" name="updateDate" type="hidden" value="${cbsContractPage.updateDate }">
<div class="subtitle">
	<p>合同基本信息</p>
	<table class="nobordertable noborder">
		<tbody>
		<tr>
			<td class="al_r" width="20%">
				<label>合同名称:</label>
			</td>
			<td width="30%">
				<input id="contractName" name="contractName" type="text" style="width: 300px" class="inputxt" value="${cbsContractPage.contractName }" readonly="readonly">
			</td>
			<td class="al_r" width="20%">
				<label>甲方名称:</label>
			</td>
			<td width="30%">
				<input id="clientName" name="clientName" type="text" style="width: 300px" class="inputxt" value="${cbsContractPage.clientName }" readonly="readonly">
			</td>
		</tr>
		<tr>
			<td class="al_r" width="20%">
				<label>合同编号:</label>
			</td>
			<td width="30%">
				<input id="contractCode" name="contractCode" type="hidden" style="width: 300px"
					   class="inputxt" datatype="*" ajaxurl="cbsContractController.do?checkInfo" value="${cbsContractPage.contractCode }">
				<span>${cbsContractPage.contractCode }</span>
			</td>
			<td class="al_r" width="20%">
				<label>合同类型:</label>
			</td>
			<td width="30%">
					<%--<t:dictSelect field="contractType" id="contractType" defaultVal='${cbsContractPage.contractType}' type="select" typeGroupCode="<%=StaticValue.CBS_CONTRACT_TYPE %>"  />--%>
				<c:if test="${cbsContractPage.contractType==1}"><span>维保合同</span></c:if>
				<c:if test="${cbsContractPage.contractType==2}"><span>销售合同</span></c:if>
				<c:if test="${cbsContractPage.contractType==3}"><span>模板合同</span></c:if>
				<c:if test="${cbsContractPage.contractType==4}"><span>其他</span></c:if>
					<%--<select>
                        <option>维保合同</option>
                        <option>销售合同</option>
                        <option>模板合同</option>
                        <option>其他</option>
                    </select>--%>
			</td>
		</tr>
		<tr>
			<td class="al_r" width="20%">
				<label>合同生效日期:</label>
			</td>
			<td width="30%">
					<%--<input class="Wdate"  onClick="WdatePicker()"/>--%>
				<input class="Wdate" id="contractDate" name="contractDate" type="text" style="width: 150px" class="inputxt"
					   value="<fmt:formatDate  value="${cbsContractPage.contractDate }" type="both" pattern="yyyy-MM-dd" />" readonly="readonly">
			</td>
			<td class="al_r" width="20%">
				<label>合同状态:</label>
			</td>
			<td width="30%">
				<c:if test="${cbsContractPage.status==0}"><span>正常</span></c:if>
				<c:if test="${cbsContractPage.status==1}"><span>已撤销</span></c:if>
			</td>
		</tr>
		<tr>
			<td class="al_r" width="20%">
				<label>付款状态:</label>
			</td>
			<td width="30%">
					<%--<t:dictSelect field="payStatus" id="payStatus" type="select" typeGroupCode="<%=StaticValue.CBS_CONTRACT_PAYSTATUS %>"  />--%>
				<input type="hidden"  id="pay" value="${cbsContractPage.payStatus }">
				<select name="payStatus" id="payStatus" disabled="disabled">
					<option value="1">未付款</option>
					<option value="2">已付款</option>
				</select>
			</td>
			<td class="al_r" width="20%">
				<label>付款日期:</label>
			</td>
			<td width="30%">
					<%--<input class="Wdate"  onClick="WdatePicker()"/>--%>
				<input class="Wdate" id="payDate" name="payDate" type="text" style="width: 150px" class="inputxt"
					   value="<fmt:formatDate  value="${cbsContractPage.payDate }" type="both" pattern="yyyy-MM-dd" />" readonly="readonly">
				<span>${cbsContractPage.payCircle }</span>
			</td>
		</tr>
		<tr>
			<td class="al_r" width="20%">
				<label>合同签署人:</label>
			</td>
			<td width="30%">
				<input id="contractSignUser" name="contractSignUser" type="text" style="width: 150px" class="inputxt" value="${cbsContractPage.contractSignUser }" readonly="readonly">
			</td>
			<td class="al_r" valign="top" width="20%">备注:</td>
			<td width="30%">
				<textarea style="width: 90%; height: 60px;" class="inputxt" id="memo" name="memo" readonly="readonly">${cbsContractPage.memo }</textarea>
			</td>
		</tr>
		</tbody>
	</table>
</div>
<table class="ftable">
	<div class="subtitle">
		<p>SLA</p>
		<div style="width: 98%; margin: 5px auto;">
				<%--<a href="#" class="easyui-linkbutton l-btn" onclick="selectContractTemplate();">选择合同模板</a>--%>
				<%--<td class="value" style="width: 500px;">
                    <input name="" id="slcontractCode" type="hidden">
                    <input name="slcontractName" id="contractName" class="inputxt" readonly="readonly" datatype="*" style="width:260px;"/>
                    &lt;%&ndash;fun="cinemaChooseBack"&ndash;%&gt;
                    <t:choose hiddenName="contractCode" hiddenid="id" url="cbsContractController.do?selectContractTemplate" name="cbsContractList" height="500px" width="500px"
                              icon="icon-search" title="选择合同模板" textname="contractName" isclear="true"></t:choose>
                </td>--%>

		</div>
	</div>
	<tbody>
	<tr>
		<th>服务条款</th>
		<th>是否包含</th>
		<th>选项</th>
		<th>标准项目</th>
		<th>增减项/说明</th>
	</tr>
	<c:forEach items="${slaList}" var="sla" varStatus="a">
		<tr>
			<td><input type="hidden" name="slaId" value="${sla.id}">${sla.serviceName}</td>
			<td>
				<input type="checkbox" name="contain" id="${sla.id}" value="${sla.contain}" disabled="disabled"/>
			</td>
			<td>
					<%--<t:dictSelect field="serviceItem" defaultVal='${sla.serviceItem}' type="select" typeGroupCode="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>"  />--%>
					<%--<input id="serviceItem" name="serviceItem" type="text" style="width: 150px" class="inputxt" value='${sla.serviceItem}'>--%>
				<select style="width:auto;"  name="serviceItem" disabled="disabled">
					<c:forEach items="${sla.serviceItems }" var="a">
						<option value="${a}" <c:forEach items="${sItemList}" var="b"><c:if test="${sla.id==b.slaId.id}"><c:if test="${b.sItem==a}">selected="selected"</c:if></c:if></c:forEach> >${a}</option>
					</c:forEach>
				</select>
			</td>
			<td>
				<c:if test="${empty sla.descrip}">
					${sla.description}
				</c:if>
					${sla.descrip}
			</td>
			<td><textarea style="width: 90%;" id="supplement" readonly="readonly" name="supplement"><c:if test="${empty sla.supple}">${sla.supplement}</c:if>${sla.supple}</textarea></td>
		</tr>
	</c:forEach>
	</tbody>
</table>
<table class="nobordertable noborder">
	<tbody>
	<tr>
		<td class="al_r" width="20%">
			<label>维修派单规则:</label>
		</td>
		<td width="30%">
			<input type="hidden" id="provider" value="${cbsContractPage.repairProvider}">
			<select style="width:auto;" name="repairProvider" id="repairProvider" defaultVal='${cbsContractPage.repairProvider}' disabled="disabled">
				<c:forEach items="${tsDeparts }" var="depart">
					<option value="${depart.orgCode }">${depart.shortname }</option>
				</c:forEach>
			</select>
			<input type="hidden" id="type" value="${cbsContractPage.repairType}">
			<select style="width:auto;" name="repairType" id="repairType" defaultVal='${cbsContractPage.repairType}' disabled="disabled">
				<option value="1">推荐</option>
				<option value="2">指定</option>
			</select>
		</td>
		<td class="al_r" width="20%">
			<label>巡检派单规则:</label>
		</td>
		<td width="30%">
			<input type="hidden" id="inspection" value="${cbsContractPage.inspectionProvider}">
			<select style="width:auto;" name="inspectionProvider" id="inspectionProvider" defaultVal='${cbsContractPage.inspectionProvider}' disabled="disabled">
				<c:forEach items="${tsDeparts }" var="depart">
					<option value="${depart.orgCode }">${depart.shortname }</option>
				</c:forEach>
			</select>
			<input type="hidden" id="it" value="${cbsContractPage.inspectionType}">
			<select style="width:auto;" name="inspectionType" id="inspectionType" defaultVal='${cbsContractPage.inspectionType}' disabled="disabled">
				<option value="1">推荐</option>
				<option value="2">指定</option>
			</select>
		</td>
	</tr>
	<tr>
		<td class="al_r" valign="top"><label>特别服务承诺:</label></td>
		<td colspan="3">
			<textarea style="width: 90%; height: 60px;" name="serviceCommitment" id="serviceCommitment" readonly="readonly">${cbsContractPage.serviceCommitment}</textarea>
		</td>
	</tr>
	<tbody/>
</table>
<div class="subtitle">
	<p>MC关联设备</p>
	<table class="ftable" id="ftable">
		<tbody>
		<tr>
			<th>设备序列号</th>
			<th>机型</th>
			<th>维保开始时间</th>
			<th>维保截止时间</th>
			<th>系统MC</th>
			<th>生效状态</th>
				<%--<th>操作</th>--%>
		</tr>
		<c:forEach items="${mcList}" var="mc" varStatus="a">
			<tr>
				<td>
					<c:if test="${mc.status==1}"><input type="hidden" name="mid" value="${mc.id}"></c:if>
						${mc.sn}
				</td>
				<td>
						${mc.equipmentType}
				</td>
				<td>
					<c:if test="${mc.status!=1}"><input style="width: 70px;" value="${mc.serviceStartDate}" readonly="readonly"/></c:if>
					<c:if test="${mc.status==1}"><input style="width: 70px;" name="serviceStartDate" value="${mc.serviceStartDate}" readonly="readonly"/></c:if>
				</td>
				<td>
					<c:if test="${mc.status!=1}"><input style="width: 70px;" value="${mc.serviceEndDate}" readonly="readonly"/></c:if>
					<c:if test="${mc.status==1}"><input style="width: 70px;" name="serviceEndDate" value="${mc.serviceEndDate}" readonly="readonly"/></c:if>
				</td>
				<td>
					<c:if test="${mc.status!=1}"><input style="width: 70px;" value="${mc.mcCode}" readonly="readonly"/></c:if>
					<c:if test="${mc.status==1}"><input style="width: 70px;" name="mcCode" value="${mc.mcCode}" readonly="readonly"/></c:if>
				</td>
				<td>
					<c:if test="${mc.status==1}"><span name="mcStatus">未生效</span></c:if>
					<c:if test="${mc.status==2}"><span name="mcStatus" style="color: red">生效中</span></c:if>
					<c:if test="${mc.status==3}"><span name="mcStatus">正常</span></c:if>
					<c:if test="${mc.status==4}"><span name="mcStatus">已失效</span></c:if>
				</td>
					<%--<td>
                        <c:if test="${mc.status!=1}"></c:if>
                        <c:if test="${mc.status==1}"><a href="#" onclick="delMc('${mc.id}')">【删除】</a></c:if>
                    </td>--%>
			</tr>
		</c:forEach>
		</tbody>
	</table>
		<%--<table class="nobordertable noborder">
            <tr>
                <td colspan="3" style="text-align: right;">
                    <a href="#" class="easyui-linkbutton l-btn" onclick="save()">保存</a>
                    <input type="hidden" onclick="saveTaskProperties()" id="realUpdate" name="realUpdate" value="1">

                </td>
                <td  style="text-align: left;">
                    <a class="easyui-linkbutton l-btn" id="revoke" onclick="revoke()">撤销</a>
                </td>
            </tr>
        </table>--%>
	</t:formvalid>
</body>
<script type="text/javascript">
    //编写自定义JS代码
    //回显复选框
    var arry=new Array();
    <c:forEach items="${slaIdListbySql }" var="sla">
    arry.push("${sla}");
    </c:forEach>
    for(var i=0;i<arry.length;i++){
        $("[name='contain']").each(function (){
            if($(this).attr("ID")==arry[i]){
                $(this).attr("checked",true);
            }
        })
    }
    $("[name='mcStatus']").each(function (){
        var mcStatus=$(this).text();
        var contractStatus=${cbsContractPage.contractType};
        if(mcStatus=='正常'||mcStatus=='已失效'){
            if(contractStatus!=3){
                $("#revoke").hide();
            }
        }
    });

    //回显下拉列表
    var repairProviders = $("#repairProvider").find("option");
    var provider=$("#provider").val();
    for (var j = 0; j < repairProviders.length; j++) {
        if ($(repairProviders[j]).val() ==provider) {
            $(repairProviders[j]).attr("selected", "selected");
        }
    }
    var repairTypes = $("#repairType").find("option");
    var type=$("#type").val();
    for (var j = 0; j < repairTypes.length; j++) {
        if ($(repairTypes[j]).val() ==type) {
            $(repairTypes[j]).attr("selected", "selected");
        }
    }
    var inspectionProviders = $("#inspectionProvider").find("option");
    var inspection=$("#inspection").val();
    for (var j = 0; j < inspectionProviders.length; j++) {
        if ($(inspectionProviders[j]).val() ==inspection) {
            $(inspectionProviders[j]).attr("selected", "selected");
        }
    }
    var inspectionTypes = $("#inspectionType").find("option");
    var it=$("#it").val();
    for (var j = 0; j < inspectionProviders.length; j++) {
        if ($(inspectionTypes[j]).val() ==it) {
            $(inspectionTypes[j]).attr("selected", "selected");
        }
    }
    var payStatuss = $("#payStatus").find("option");
    var pay=$("#pay").val();
    for (var j = 0; j < payStatuss.length; j++) {
        if ($(payStatuss[j]).val() ==pay) {
            $(payStatuss[j]).attr("selected", "selected");
        }
    }
</script>
<script type="text/javascript">
    /*function save() {
        //var obj = new Object();
        $("[name='contain']").each(function (){
            if($(this).prop('checked')==true){
                $(this).val(1);
            }else{
                $(this).val(2);
            }
        })
        var id=$("#id").val();
        var contractCode = $("#contractCode").val();
        var contractType = $("#contractType").val();
        var contractName = $("#contractName").val();
        var clientName = $("#clientName").val();
        var contractDate = $("#contractDate").val();
        var payStatus = $("#payStatus").val();
        var payDate = $("#payDate").val();
        var contractSignUser = $("#contractSignUser").val();
        var memo = $("#memo").val();
        var repairProvider = $("#repairProvider").val();
        var repairType = $("#repairType").val();
        var inspectionProvider = $("#inspectionProvider").val();
        var inspectionType = $("#inspectionType").val();
        var serviceCommitment = $("#serviceCommitment").val();
       // console.log(JSON.stringify(obj));
        //var cbsContractMcEquipmentEntity = new Object();
        var mid=[];
        var m=0;
        $("[name='mid']").each(function (){
            mid[m]=$(this).val();
            m++;
        });
        var serviceStartDate=[];
        var s=0;
        $("[name='serviceStartDate']").each(function (){
            serviceStartDate[s]=$(this).val();
            s++;
        });
        var serviceEndDate=[];
        var e=0;
        $("[name='serviceEndDate']").each(function (){
            serviceEndDate[e]=$(this).val();
            e++;
        });
        var mcCode=[];
        var c=0;
        $("[name='mcCode']").each(function (){
            mcCode[c]=$(this).val();
            c++;
        });
        var contain=[];
        var z=0;
        $("[name='contain']").each(function (){
            contain[z]=$(this).val();
            z++;
        });
        var slaIds=[];
        var y=0;
        $("[name='slaId']").each(function (){
            slaIds[y]=$(this).val();
            y++;
        });
        var serviceItems=[];
        var a=0;
        $("[name='serviceItem']").each(function (){
            serviceItems[a]=$(this).val();
            a++;
        });
        //console.log(JSON.stringify(cbsContractMcEquipmentEntity));
        $.dialog({
            content: "url:cbsContractController.do?realUpdate",
            zIndex: 2100,
            title: '修改确认',
            lock: true,
            width: '800px',
            height: '500px',
            left: '85%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },
            button: [{
                name: '修改确认',
                callback: function () {
                    $.ajax({
                        url: "cbsContractController.do?doUpdate",
                        data: {
                            "id":id,
                            "contractCode":contractCode,
                            "contractType":contractType,
                            "contractName":contractName,
                            "clientName":clientName,
                            "contractDate":contractDate,
                            "payStatus":payStatus,
                            "contractSignUser":contractSignUser,
                            "payDate":payDate,
                            "memo":memo,
                            "repairProvider":repairProvider,
                            "repairType":repairType,
                            "inspectionProvider":inspectionProvider,
                            "inspectionType":inspectionType,
                            "serviceCommitment":serviceCommitment,
                            "mid":mid,
                            "serviceStartDate":serviceStartDate,
                            "serviceEndDate":serviceEndDate,
                            "mcCode":mcCode,
                            "contain":contain,
                            "slaIds":slaIds,
                            "serviceItems":serviceItems,
                        },
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        traditional:true,
                        error : function() {// 请求失败处理函数
                        },
                        success : function(data) {
                            window.location = "cbsContractController.do?cbsContract&code=update";
                        }
                    });
                },
                focus: true
            }, {
                name: '返回',
                callback: function () {
                }
            }]
        });
    }
    function revoke(){
        var flag=true;
        var contractStatus=${cbsContractPage.contractType}
         $("[name='mcStatus']").each(function (){
             var mcStatus=$(this).text();
             if(mcStatus=='生效中'&&contractStatus!=3){
                 tip("MC记录中有已生效的不能撤销合同");
                 flag=false;
			 }
         });
         if(flag||contractStatus==3){
             var id=$("#id").val();
             var mid=[];
             var m=0;
             $("[name='mid']").each(function (){
                 mid[m]=$(this).val();
                 m++;
             });
             var re="撤销";
             $.dialog({
                 content: "url:cbsContractController.do?revoke&id="+id,
                 zIndex: 2100,
                 title: '确认信息',
                 lock: true,
                 width: '800px',
                 height: '500px',
                 left: '50%',
                 top: '50%',
                 opacity: 0.4,
                 init: function () {
                     top.myWindow = window;
                 },
                 button: [{
                     name: '确认',
                     callback: function () {
                         var cancelDes=$.session.get('cancelDes');
                         if(cancelDes==null||cancelDes==""){
							tip("请填写撤销原因")
							 return;
						 }
                         $.ajax({
                             url: "cbsContractController.do?doUpdate",
                             data: {
                                 "id":id,
                                 "mid":mid,
                                 "re":re,
								 "cancelDes":cancelDes,
                             },
                             cache: false,
                             dataType: 'json',
                             type: 'POST',
                             traditional:true,
                             error : function() {// 请求失败处理函数
                             },
                             success : function(data) {
                                 window.location = "cbsContractController.do?cbsContract&code=recoke";
                                 /!*var d = $.parseJSON(data);
                                 console.log(d);
                                 alert(d)
                                 if (d.success) {
                                     window.location = "cbsContractController.do?cbsContract&code=update";
                                 }else{
                                     return false;
                                 }*!/
                             }
                         });
                     },
                     focus: true
                 }, {
                     name: '返回',
                     callback: function () {
                     }
                 }]
             });
		 }
     }
     function delMc(mid){
         $.ajax({
             url: "cbsContractController.do?delMc",
             data: {
					"mid":mid,
             },
             cache: false,
             dataType: 'json',
             type: 'POST',
             traditional:true,
             error : function() {// 请求失败处理函数
             },
             success : function(data) {
                 /!*alert(data)
                 var d = $.parseJSON(data);
                 console.log(d)*!/;
                 if (data.success) {
                     window.location.reload();
                 }else{
                     return false;
                 }
             }
         });
	 }*/
</script>
<script src = "webpage/com/zybk/cbscontract/cbsContract.js"></script>